using Microsoft.AspNetCore.Mvc;
using ZR.Model.Dto;
using ZR.Model.Business;
using ZR.Service.Business.IBusinessService;
using ZR.Admin.WebApi.Filters;

//创建时间：2023-09-11
namespace ZR.Admin.WebApi.Controllers
{
    /// <summary>
    /// 土地出让公告信息
    /// </summary>
    [Verify]
    [Route("business/dealBehaviorInfo")]
    public class V3TdsyqDealBehaviorInfoController : BaseController
    {
        /// <summary>
        /// 土地出让公告信息接口
        /// </summary>
        private readonly IV3TdsyqDealBehaviorInfoService _V3TdsyqDealBehaviorInfoService;

        public V3TdsyqDealBehaviorInfoController(IV3TdsyqDealBehaviorInfoService V3TdsyqDealBehaviorInfoService)
        {
            _V3TdsyqDealBehaviorInfoService = V3TdsyqDealBehaviorInfoService;
        }

        /// <summary>
        /// 查询土地出让公告信息列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet("list")]
        [ActionPermissionFilter(Permission = "business:v3tdsyqdealbehaviorinfo:list")]
        public IActionResult QueryV3TdsyqDealBehaviorInfo([FromQuery] V3TdsyqDealBehaviorInfoQueryDto parm)
        {
            var response = _V3TdsyqDealBehaviorInfoService.GetList(parm);
            return SUCCESS(response);
        }


        /// <summary>
        /// 查询土地出让公告信息详情
        /// </summary>
        /// <param name="TdcrggId"></param>
        /// <returns></returns>
        [HttpGet("{TdcrggId}")]
        [ActionPermissionFilter(Permission = "business:v3tdsyqdealbehaviorinfo:query")]
        public IActionResult GetV3TdsyqDealBehaviorInfo(long TdcrggId)
        {
            var response = _V3TdsyqDealBehaviorInfoService.GetInfo(TdcrggId);
            
            var info = response.Adapt<V3TdsyqDealBehaviorInfo>();
            return SUCCESS(info);
        }

        /// <summary>
        /// 添加土地出让公告信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ActionPermissionFilter(Permission = "business:v3tdsyqdealbehaviorinfo:add")]
        [Log(Title = "土地出让公告信息", BusinessType = BusinessType.INSERT)]
        public IActionResult AddV3TdsyqDealBehaviorInfo([FromBody] V3TdsyqDealBehaviorInfoDto parm)
        {
            var modal = parm.Adapt<V3TdsyqDealBehaviorInfo>().ToCreate(HttpContext);

            var response = _V3TdsyqDealBehaviorInfoService.AddV3TdsyqDealBehaviorInfo(modal);

            return SUCCESS(response);
        }

        /// <summary>
        /// 更新土地出让公告信息
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        [ActionPermissionFilter(Permission = "business:v3tdsyqdealbehaviorinfo:edit")]
        [Log(Title = "土地出让公告信息", BusinessType = BusinessType.UPDATE)]
        public IActionResult UpdateV3TdsyqDealBehaviorInfo([FromBody] V3TdsyqDealBehaviorInfoDto parm)
        {
            var modal = parm.Adapt<V3TdsyqDealBehaviorInfo>().ToUpdate(HttpContext);
            var response = _V3TdsyqDealBehaviorInfoService.UpdateV3TdsyqDealBehaviorInfo(modal);

            return ToResponse(response);
        }

        /// <summary>
        /// 删除土地出让公告信息
        /// </summary>
        /// <returns></returns>
        [HttpDelete("{ids}")]
        [ActionPermissionFilter(Permission = "business:v3tdsyqdealbehaviorinfo:delete")]
        [Log(Title = "土地出让公告信息", BusinessType = BusinessType.DELETE)]
        public IActionResult DeleteV3TdsyqDealBehaviorInfo(string ids)
        {
            int[] idsArr = Tools.SpitIntArrary(ids);
            if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); }

            var response = _V3TdsyqDealBehaviorInfoService.Delete(idsArr);

            return ToResponse(response);
        }

        /// <summary>
        /// 导出土地出让公告信息
        /// </summary>
        /// <returns></returns>
        [Log(Title = "土地出让公告信息", BusinessType = BusinessType.EXPORT, IsSaveResponseData = false)]
        [HttpGet("export")]
        [ActionPermissionFilter(Permission = "business:v3tdsyqdealbehaviorinfo:export")]
        public IActionResult Export([FromQuery] V3TdsyqDealBehaviorInfoQueryDto parm)
        {
            parm.PageNum = 1;
            parm.PageSize = 100000;
            var list = _V3TdsyqDealBehaviorInfoService.GetList(parm).Result;
            if (list == null || list.Count <= 0)
            {
                return ToResponse(ResultCode.FAIL, "没有要导出的数据");
            }
            var result = ExportExcelMini(list, "土地出让公告信息", "土地出让公告信息");
            return ExportExcel(result.Item2, result.Item1);
        }

        /// <summary>
        /// 土地出让公告粤公平新增
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet("themeAdd/{id}")]
        [ActionPermissionFilter(Permission = "business:v3tdsyqdealbehaviorinfo:themeAdd")]
        [Log(Title = "粤公平新增", BusinessType = BusinessType.INSERT)]

        public IActionResult ThemeAddDealBehaviorInfo(long id)
        {
            var response = _V3TdsyqDealBehaviorInfoService.PushAddTheme(id);


            return SUCCESS(response);
        }


    }
}